import com.mysql.jdbc.Connection;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DelCity {
    public static void main(String[] args) throws SQLException {
        //1.获得数据源
        MysqlDataSource dataSource=new MysqlDataSource();
        dataSource.setURL("jdbc:mysql://127.0.0.1:3306/java33?characterEncoding=utf8&useSSL=true");
        dataSource.setUser("root");
        dataSource.setPassword("123456");
        //2.获得连接
        Connection connection= (Connection) dataSource.getConnection();
        //3.获得执行器，组装SQL
        String delSql="delete from city where id=?";
        PreparedStatement statement=connection.prepareStatement(delSql);
        statement.setInt(1,2);
        //4.执行SQL
        int result=statement.executeUpdate();
        System.out.println("受影响的行数为："+result);
        //5.关闭资源
        statement.close();
        connection.close();

    }
}
